import { app } from "../../utils";

/** 权限指令 */
export const auth = {
  mounted(el:any, binding:any) {
    const value = binding.value || binding.arg;
    const jud = judAuth(value);
    if (!jud) {
      el.parentNode && el.parentNode.removeChild(el);
    }
  }
};

/** 判断是否有此权限 */
export function judAuth(code: string | string[]) {
  const authCode:any = app.route.meta.auth || []; // 添加空值检查
  if (typeof code === 'string') {
    return authCode.includes(code); // 使用 includes 方法
  } else {
    return code.some((cod: any) => authCode.includes(cod)); // 使用 some 方法简化逻辑
  }
}
